﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using AMG.Common;
using AMG.DALProfile;

namespace AMG.Web
{
    public partial class ChangePwd : AMG.Web.UI.Page.UserPage
    {
        public string companyname = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlParameter para=new SqlParameter ("@UserID",UserID);
            companyname = (DbHelper.ExecuteScalar(CommandType.Text, "SELECT  UserName, ID FROM AMG_Proxy where ID=@UserID", para)).ToString();
            DataBind();

            if (Request.Form["password1"] != null)
            {
                try
                {
                    SqlParameter[] para1 ={
                        new SqlParameter("@UserID", SqlDbType.NVarChar,10),
					   	new SqlParameter("@Password", SqlDbType.NVarChar,200),
                    };
                    para1[0].Value = UserID;
                    para1[1].Value = Input.MD5(Request.Form["password1"]);
                    DbHelper.ExecuteNonQuery(CommandType.Text, "update AMG_proxy set Password=@Password where ID=@UserID", para1);
                }
                catch
                {
                    Response.Redirect("/optionfail.aspx");
                }
                AMG.BLL.User.User us = new AMG.BLL.User.User();
                us.Login(UserID.ToString (), Request.Form["password1"]);
                AMG.Web.UI.Page.UserPage.SetCookie(UserID, Input.MD5(Request.Form["password1"], false));
                Response.Redirect("/optionok.aspx");
            }
        }
    }
}
